package ro.ubbcluj.cs.damate.persistence.repository;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import ro.ubbcluj.cs.damate.persistence.entities.Task;
import ro.ubbcluj.cs.damate.persistence.entities.User;

import java.util.List;

/**
 * @author Lóránd Fazakas (lorand)
 *         Date: 5/10/12
 *         Time: 9:25 PM
 */
public interface TaskRepository extends CrudRepository<Task, Long> {

    @Query("select t from Task t")
    List<Task> findAll();

    @Query("select t from Task t inner join t.section s inner join s.teams te where ?1 member te.members")
    List<Task> findByUser(User user);

    @Query("select distinct t from Task t left join fetch t.assignedObjects where t.taskId = ?1")
    Task loadTaskWithRelatedObjects(Long taskId);
}
